package com.synway.consume;

import com.synway.service.HouseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component
@RabbitListener(queues = "SPIDER_QUEUE")
@Slf4j
@Order(20)
public class HouseConsume {
    @Autowired
    private HouseService houseService;

    @RabbitHandler
    public void recived(String msg) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate now = LocalDate.now();
        String localTime = df.format(now);
        houseService.deleteData(msg, localTime);
        houseService.spiderToDB(msg);
        //入库后删除文件夹
        houseService.deleteFiles(localTime,msg);
    }

}
